package com.sbw.springcloud.consumer.ribbon.demo.controller;

import com.sbw.springcloud.consumer.ribbon.demo.service.RibbonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: sangbowei
 * @Description:  ribbon 示例控制器
 * @Date: Created in  17:53 2017\12\28 0028
 **/
@RestController
public class RibbonControler {

    Logger logger = LoggerFactory.getLogger(RibbonControler.class);

    @Autowired
    RibbonService ribbonService;

    @RequestMapping(value="/ribbon_discovery_client")
    public String ribbonDiscoveryClient() {
        String result = ribbonService.ribbonDiscoveryClient();
        logger.info(result);
        return result;
    }

    @GetMapping("/ribbon_hello")
    public String ribbonHello() {
        String result = ribbonService.ribbonHello();
        logger.info(result);
        return result;
    }

    @GetMapping("/ribbon_hello_delay")
    public String ribbonHelloDelay() {
        String result = ribbonService.ribbonHelloDelay();
        logger.info(result);
        return result;
    }

    @GetMapping("/ribbon_hello_params")
    public String ribbonHelloParams(@RequestParam(value = "name") String name) {
        String result = ribbonService.ribbonHelloParams(name);
        logger.info(result);
        return result;
    }

    @GetMapping("/ribbon_hello_client")
    public String ribbonHelloClient() {
        String result = ribbonService.ribbonHelloClient();
        logger.info(result);
        return result;
    }

    @GetMapping("/test_ribbon_hystrix")
    public void test(){
        for(int i=0;i<1000;i++){
            ribbonService.ribbonDiscoveryClient();
        }

        for(int i=0;i<2000;i++){
            ribbonService.ribbonHello();
        }

        for(int i=0;i<500;i++){
            ribbonService.ribbonHelloClient();
        }

        for(int i=0;i<100;i++){
            ribbonService.ribbonHelloDelay();
        }

        for(int i=0;i<10000;i++){
            ribbonService.ribbonHelloParams(""+i);
        }
    }


}
